<!--
 * @Author: 'yangyuhang1203' '2621131059@qq.com'
 * @Date: 2025-09-09 10:16:20
 * @LastEditors: 'yangyuhang1203' '2621131059@qq.com'
 * @LastEditTime: 2025-09-09 11:13:19
 * @FilePath: \企业级\前端\js\js语句.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>流程控制</title>
</head>
<body>
    <div id="did" style="color: blue;font-size: 20px;">
        Hello World
    </div>
    <div>
        您喜欢的水果：<input id="myInput" type="text" value="Banana">
    </div>
    <script>
        //if语句
        var hour = new Date().getHours();
        if(hour>9){
            //获取页面上的元素
            var oDiv = document.getElementById("did");
            oDiv.innerHTML = "现在是早上";
        }
        //witch语句
        var text;
        //获取页面上的输入框元素
        var oInput = document.getElementById("myInput");
        //获取输入框里的值
        var fruits = oInput.value;
        switch(fruits) {
            case "Banana":
            text = "香蕉很好吃!";
            break;
            case "Orange":
            text = "橘子很好吃";
            break;
            case "Apple":
            text = "苹果很好吃";
            break;
            default:
            text = "I have never heard of that fruit...";
        }
        alert(text);
        document.write("<br>");
        //for循环
        var text="";
        var sum = 0;
        for(var i = 1;i <6;i++){
            sum+=i;
            text+="这是第"+i+"次循环，得到的和为"+sum+"<br>";

        }
        document.write(text);
        document.write("<br>");

        //while循环
        var text="";
        var i = 10;
        while(i>5){
            text += "<br>The number is " + i;
            i--;
        }
        document.write(text);
        document.write("<br>");
    </script>
</body>
</html>